package com.zhkj.txg.module.home.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.txg.module.cart.entity.CartResponse
import com.zhkj.txg.module.home.entity.*
import io.reactivex.disposables.Disposable
import retrofit2.http.Field

class HomeManager : BaseManager<HomeApi>(HomeApi::class.java) {

    /**
     * 获取首页数据
     */
    fun homeData(
        map: Map<String, String>?,
        listener: SubscribeListener<HomeResponse>
    ): Disposable {
        val homeData = apiService.homeData(map)
        return subscribe(homeData, ResponseSubscribeListener(listener))
    }

    /**
     * 门店列表
     */
    fun getShopList(
        map: Map<String, String>?,
        listener: SubscribeListener<ShopListResponse>
    ): Disposable {
        val homeData = apiService.getShopList(map)
        return subscribe(homeData, ResponseSubscribeListener(listener))
    }

    /**
     * 获取热门商品
     */
    fun hotGoods(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<HotGoodsResponse>
    ): Disposable {
        val hotGoods = apiService.hotGoods(token, page, numb)
        return subscribe(hotGoods, ResponseSubscribeListener(listener))
    }

    /**
     * 获取尖货首页数据
     */
    fun topData(token: String, listener: SubscribeListener<TopDataResponse>): Disposable {
        val topData = apiService.topData(token)
        return subscribe(topData, ResponseSubscribeListener(listener))
    }

    /**
     * 获取尖货热卖商品
     */
    fun topProduct(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<TopProductResponse>
    ): Disposable {
        val topProduct = apiService.topProduct(token, page, numb)
        return subscribe(topProduct, ResponseSubscribeListener(listener))
    }

    /**
     * 获取超市首页数据
     */
    fun marketData(token: String, listener: SubscribeListener<TopDataResponse>): Disposable {
        val marketData = apiService.marketData(token)
        return subscribe(marketData, ResponseSubscribeListener(listener))
    }

    /**
     * 获取超市热卖商品
     */
    fun marketProduct(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<TopProductResponse>
    ): Disposable {
        val marketProduct = apiService.marketProduct(token, page, numb)
        return subscribe(marketProduct, ResponseSubscribeListener(listener))
    }

    /**
     * 获取超市分类
     */
    fun marketCate(
        token: String, catId: Int, listener: SubscribeListener<MarketCateResponse>
    ): Disposable {
        val marketCate = apiService.marketCate(token, catId)
        return subscribe(marketCate, ResponseSubscribeListener(listener))
    }

    /**
     * 搜索商品
     */
//    fun searchProduct(
//        token: String, shopId: Int, catId: Int, shopCatId: Int, sort: String,
//        asc: String, type: Int, searchKey: String, page: Int, numb: Int,
//        listener: SubscribeListener<SearchProductResponse>
//    ): Disposable {
//        val searchProductList = apiService.searchProductList(
//            token, shopId, catId, shopCatId, sort, asc, type,
//            searchKey, page, numb
//        )
//        return subscribe(searchProductList, ResponseSubscribeListener(listener))
//    }

    fun searchProduct(
        token: String,
        shopId: Int,
        activeType: Int?,
        search: String?,
        catId: Int?,
        sort: String?,
        sortAsc: String?,
        page: String,
        rows: String,
        recommend: Int?,
        listener: SubscribeListener<SearchProductResponse>
    ): Disposable {
        val searchProductList = apiService.searchProductList(
            token, shopId, activeType, search, catId, sort, sortAsc, page, rows, recommend
        )
        return subscribe(searchProductList, ResponseSubscribeListener(listener))
    }

    /**
     * 获取所有分类
     */
    fun categoryAll(listener: SubscribeListener<CategoryAllResponse>): Disposable {
        val categoryAll = apiService.categoryAll()
        return subscribe(categoryAll, ResponseSubscribeListener(listener))
    }

    /**
     * 获取商城数据
     */
    fun mallData(token: String, listener: SubscribeListener<MallResponse>): Disposable {
        val mallData = apiService.mallData(token)
        return subscribe(mallData, ResponseSubscribeListener(listener))
    }

    /**
     * 获取商城店铺列表
     */
    fun mallShopList(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<MallShopResponse>
    ): Disposable {
        val mallShopList = apiService.mallShopList(token, page, numb)
        return subscribe(mallShopList, ResponseSubscribeListener(listener))
    }

    /**
     * 商城分类列表
     */
    fun mallCategoryList(
        token: String,
        catId: Int,
        type: Int,
        page: Int,
        numb: Int,
        listener: SubscribeListener<MallCategoryResponse>
    ): Disposable {
        val mallCategory = apiService.mallCategory(token, catId, type, page, numb)
        return subscribe(mallCategory, ResponseSubscribeListener(listener))
    }

    /**
     * 获取店铺详情
     */
    fun shopDetail(
        token: String,
        shopId: Int,
        listener: SubscribeListener<ShopResponse>
    ): Disposable {
        val shopDetail = apiService.shopDetail(token, shopId)
        return subscribe(shopDetail, ResponseSubscribeListener(listener))
    }

    /**
     * 关注，取消关注店铺
     */
    fun followShop(
        token: String,
        shopId: Int,
        listener: SubscribeListener<ShopFollowResponse>
    ): Disposable {
        val followShop = apiService.followShop(token, shopId)
        return subscribe(followShop, ResponseSubscribeListener(listener))
    }

    /**
     * 获取店铺分类
     */
    fun shopCate(
        shopId: Int,
        listener: SubscribeListener<ShopCategoryResponse>
    ): Disposable {
        val shopCate = apiService.shopCate(shopId)
        return subscribe(shopCate, ResponseSubscribeListener(listener))
    }

    /**
     * 商家入驻
     */
    fun merchantRegister(
        token: String,
        name: String,
        gender: Int,
        age: String,
        mobile: String,
        reason: String,
        license: String,
        identifyFront: String,
        identifyBack: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val merchantRegister = apiService.merchantRegister(
            token, name, gender, age, mobile, reason,
            license, identifyFront, identifyBack
        )
        return subscribe(merchantRegister, ResponseSubscribeListener(listener))
    }

    /**
     * 天兴购公益
     */
    fun welfare(listener: SubscribeListener<WelfareResponse>): Disposable {
        val welfare = apiService.welfare()
        return subscribe(welfare, ResponseSubscribeListener(listener))
    }

    /**
     * 获取配置
     */
    fun config(listener: SubscribeListener<ConfigResponse>): Disposable {
        val config = apiService.getConfig()
        return subscribe(config, ResponseSubscribeListener(listener))
    }

    /**
     * 获取版本
     */
    fun getVersion(listener: SubscribeListener<VersionResponse>): Disposable {
        val config = apiService.getVersion()
        return subscribe(config, ResponseSubscribeListener(listener))
    }

    /**
     * 获取使用帮助内容
     */
    fun guideDetail(id: Long, listener: SubscribeListener<GuideDetailResponse>): Disposable {
        val guideDetail = apiService.guideDetail(id)
        return subscribe(guideDetail, ResponseSubscribeListener(listener))
    }

    /**
     * 获取发圈素材
     */
    fun shareInfo(token: String, id: Long, listener: SubscribeListener<ShareInfoResponse>): Disposable {
        val shareInfo = apiService.shareInfo(token, id)
        return subscribe(shareInfo, ResponseSubscribeListener(listener))
    }

    /**
     * 获取商品二级分类
     */
    fun secondCate(token: String, catId: Int, listener: SubscribeListener<MarketCateResponse>): Disposable {
        val secondCate = apiService.secondCate(token, catId)
        return subscribe(secondCate, ResponseSubscribeListener(listener))
    }

    /**
     * 判断是否已申请商家入驻
     */
    fun isApply(token: String, listener: SubscribeListener<ApplyResponse>): Disposable {
        val userApply = apiService.isUserApply(token)
        return subscribe(userApply, ResponseSubscribeListener(listener))
    }

    /**
     * 绑定聊天Id
     */
    fun bindChatId(token: String, chatId: String, listener: SubscribeListener<BaseResponse>): Disposable {
        val bindChatId = apiService.bindChatId(token, chatId)
        return subscribe(bindChatId, ResponseSubscribeListener(listener))
    }

    /**
     * 加入购物车
     */
    fun addCart(
        map: Map<String, String>, listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val addCart = apiService.addCart(map)
        return subscribe(addCart, ResponseSubscribeListener(listener))
    }

    /**
     * 获取购物车列表
     */
    fun getCartNew(
        map: Map<String, String>,
        listener: SubscribeListener<CartResponse>
    ): Disposable {
        val cart = apiService.getCartNew(map)
        return subscribe(cart, ResponseSubscribeListener(listener))
    }

    /**
     * 获取活动商品
     * */
    fun getGoodsActivity(
        token: String, id: Int,
        listener: SubscribeListener<EventResponse>
    ): Disposable {
        val goodsActivity = apiService.getGoodsActivity(token, id)
        return subscribe(goodsActivity, ResponseSubscribeListener(listener))
    }

}